package com.common.email;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * 纯文本邮件服务类.
 * 
 * @author calvin
 */
//@Service
public class SimpleMailService {

	private static Logger logger = LoggerFactory
			.getLogger(SimpleMailService.class);

	@Autowired
	private JavaMailSender mailSender;
	private String textTemplate;

	/**
	 * 发送纯文本的用户修改通知邮件.
	 */
	public void sendNotificationMail(String accountName) {
		SimpleMailMessage msg = new SimpleMailMessage();
		msg.setTo("917537966@qq.com");
		msg.setSubject("账户更新通知");

		String content = String.format(textTemplate, accountName, new Date());
		msg.setText(content);

		try {
			mailSender.send(msg);
		} catch (Exception e) {
			logger.error("发送邮件失败", e);
		}
	}

	public void setTextTemplate(String textTemplate) {
		this.textTemplate = textTemplate;
	}

}
